[//lasso
	// load all ctags once per startup

	// abort if $connection does not exist	
	if(!var_defined('connection') || !var_defined('tagDir') || !var_defined('tagExt'));
		abort;
	/if;
	
	// was the refresh param sent?
	var('erRefreshtags') = boolean(action_param('erRefreshtags'));
	var('tagsLoaded' = 0);
	
	// compare to current size, only run if different

	inline($connection);		
		var('ctags') = file_listdirectory($tagDir);
		
		// remove files that start with periods
		$ctags->removeall(match_regexp('^\\..*'));
	/inline;


	// compare to current size, only run if different
	if($ctags->size != $erGlobals->find('tagfiles') || $erRefreshtags);	
		iterate($ctags, local('thisTag'));
			// begins with . or ~ igonore it
			if(!#thisTag->beginswith('~'));
				local('thisTagName' = #thisTag);
					
					#thisTagName->removetrailing($tagExt);
				
					// if not already defined (or refreshing)
					if(!lasso_tagexists(#thisTagName) || $erRefreshtags);
						// use global namespace so tags stay resident in memory
						namespace_using(namespace_global);
							protect;
								library($tagDir + #thisTag);
								$tagsLoaded += 1;
								
								// log any errors
								handle_error;
									log_critical('[Tagloader] Error loading [' + #thisTagName + ']: ' + error_msg);
								/handle_error;
							/protect;
						/namespace_using;
					else;
					// account for tags that already exist
					$tagsLoaded += 1;
					/if;

					// update global
					thread_atomic($erGlobals);
						$erGlobals->find('tagfiles') = $tagsLoaded;
					/thread_atomic;		
					
					// log results
					//log_warning('[Tagloader] ' + $tagsLoaded + ' of ' + $ctags->size + ' tags loaded successfully.');

			/if;
		/iterate;
	/if;	

]
